﻿#region Header
// ------------------------ Licence / Copyright ------------------------
// 
// ScrumTable for Scrum Meeting Support
// Copyright © HSR - Hochschule für Technik Rapperswil
// All Rights Reserved
// 
// Author:
//  Michael Gfeller Silvan Gehrig Patrick Boos
// 
// ---------------------------------------------------------------------
#endregion

#region Usings

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using ScrumTable.Common.Collections;
using ScrumTable.Common.Data;
using ScrumTable.Common.Excel.Properties;

#endregion

namespace ScrumTable.Common.Excel.OpenXmlSdk.Extensions
{
    /// <summary>
    /// Provides the additional functionalities required for Excel
    /// data management of a DataColumn instance.
    /// </summary>
    internal static class DataColumnUtil
    {
        #region Properties
        //--------------------------------------------------------------------
        // Properties
        //--------------------------------------------------------------------

        private const string PropertyNameCellReference = "CellReference";

        #endregion

        #region Methods
        //--------------------------------------------------------------------
        // Methods
        //--------------------------------------------------------------------

        internal static void SetCellRef(this DataColumn thisPtr, CellReference reference)
        {
            PreCondition.AssertNotNull(thisPtr, "thisPtr");

            thisPtr.ExtendedProperties[PropertyNameCellReference] = reference;
        }

        internal static CellReference GetCellRef(this DataColumn thisPtr)
        {
            PreCondition.AssertNotNull(thisPtr, "thisPtr");

            return thisPtr.HasCellRef()
                ? thisPtr.ExtendedProperties[PropertyNameCellReference] as CellReference
                : null;
        }

        internal static bool HasCellRef(this DataColumn thisPtr)
        {
            PreCondition.AssertNotNull(thisPtr, "thisPtr");

            return thisPtr.ExtendedProperties.ContainsKey(PropertyNameCellReference);
        }

        #endregion
    }
}